Xbasic

SYS_OPEN Function

Syntax

V SYS_OPEN(C Filename)

Arguments

Filename

The file you wish to open.

Description

Open a file using the files registered open method.

Discussion

SYS_OPEN() opens the specified Filename, using the program associated with the corresponding file type of filename. The behavior of this command is the same as Double clicking on filename in the Windows Explorer. For example, if filename is " c:\mydata\sales.xls " and the .xls extension is associated with Microsoft Excel, sys_open("c:\mydata\sales.xls") will open Excel and load the file.

Example

A button runs the following script, which retrieves the value in the field Web_site, then opens the specified URL in Internet Explorer.

dim shared v_website as C
dim URL_var as C
dim form_name as C
v_website = topparent:Web_site.value
form_name = topparent.name() + ".this"
URL_var = eval("Var->v_website", form_name)
If at("://", URL_var) = 0 then
    URL_var = "http://"+URL_var
End if
sys_open(URL_var)

This script runs a batch file.

file = "c:\batch files\backup.bat"
sys_open(file)

This script opens a Microsoft Excel file.

file = "c:\mydata\sales.xls"
sys_open(file)

This script opens an Adobe PDF file.

dim prmpt_title as C
dim prmpt_filter as C
dim prmpt_default as C
dim prmpt_flag as C
dim global vpdffile as C
dim global vpath2 as C
DIM SHARED vpdffile as C
var->path2 = ""
t5 = ""
t5 = a_db_current_path
var->Path = t5
prmpt_title = "Select PDF Document"
prmpt_filter = "*.pdf"
prmpt_default = var->path
var->vpdffile = ui_get_file( a5_eval_expression(prmpt_title), prmpt_filter, prmpt_default, "X")
if file.exists(var->vpdffile) then
    sys_open(var->vpdffile)
else
    ui_msg_box("Error Opening File", "File" + var->vpdffile + " does not exist." ,ui_stop_symbol)
end if

The following example shows how to open an image (or any other file type, such as a PDF file) with its Windows associated application. The file's path and name are stored in an ordinary character field named " fileloc ". Put this code under the OnPush event of a button.

DIM filename as C

filename = a5_eval_expression("=Fileloc") 
if file.exists(filename) then 
sys_open(filename) 
else 
ui_msg_box("Error Opening File","File '"+filename+"' does not exist.",ui_stop_symbol) 
end if

Limitations

Desktop applications only.

See Also